package com.situ.admin.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.admin.bean.GoodsPicturre;

public interface GoodsPicturreMapper {
	@Delete({ "delete from goods_picturre", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into goods_picturre ( goods_id, ", "name)", "values ( #{goodsId,jdbcType=INTEGER}, ",
			"#{name,jdbcType=VARCHAR})" })
	int insert(GoodsPicturre record);

	@Select({ "select", "id, goods_id, name", "from goods_picturre", "where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR) })
	GoodsPicturre selectByPrimaryKey(Integer id);

	@Select({ "select", "id, goods_id, name", "from goods_picturre" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR) })
	List<GoodsPicturre> selectAll();

	@Update({ "update goods_picturre", "set goods_id = #{goodsId,jdbcType=INTEGER},", "name = #{name,jdbcType=VARCHAR}",
			"where id = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(GoodsPicturre record);

	@Insert({ "<script>", "insert into goods_picturre (goods_id,name) values",
			"<foreach collection = 'pictures' item = 'pic' separator=','>", "(#{id}, #{pic.name})", "</foreach>",
			"</script>" })
	int batchInsert(@Param("id") Integer id, @Param("pictures") List<GoodsPicturre> pictures);

	@Select("select * from goods_picturre where goods_id = #{goodsId}")
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR) })
	List<GoodsPicturre> selectByGoodsId(Integer goodId);

	@Delete("delete from goods_picturre where goods_id=#{goodsId}")
	int deleteByGoodsId(Integer id);
}